<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>computed 与 watch 的区别</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>

    <div id="app">
        姓：<input v-model="firstName" type="text"><br>
        名：<input v-model="lastName" type="text"><br>
        全名：{{ fullName }}
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                firstName: '',
                lastName: '',
                fullName: ''
            },
            // computed: {
            //     fullName() {
            //         setTimeout(() => {
            //             return this.firstName + this.lastName
            //         }, 1000)
            //     }
            // }
            watch: {
                firstName(newValue) {
                    setTimeout(() => {
                        this.fullName = newValue + this.lastName
                    }, 1000)
                },
                lastName(newValue) {
                    setTimeout(() => {
                        this.fullName = this.firstName + newValue
                    }, 1000)
                }
            }
        })
    </script>

</body>
</html>